
                     Vic's QBasic Programming Tutorial

                           Basic Tutorial VIV

                            Game Tutorial II
                           Its about time huh?


-----------------------------------------------------------------------------

Lately I have been writing somewhat advanced tutorials...
Lets take a step back and talk more about game programming...

First off, Lets review...

Maybee not...  I'm sure you know what your doing...

---
In the last tutorial I said that I would talk about how to use the arrow
keys to move a sprite.  That is what I would like to cover first...

-----------------------------------------------------------------------------

Every QBasic programmer knows that there was a time in their life when all
they could do was program ASCII games...  After that phase was over you
most likely would find out how to move things around with the keyboard...
At that point you start to wonder how you could use the arrow keys that
everyone else uses in their games.  I know I did.  If you are to that point,
or you would like to skip that phase alltogether here you go!

In the last tutorial you moved things around the screen with the AWSD buttons
right?  The command was very easy...

PRESS$ = INKEY$
IF PRESS$ = "A" Then x = x - 1
IF PRESS$ = "W" Then ...


that was it...
But if you havn't noticed, you can't do that with the arrow keys...
How does it work then?  You know it's possible!
---

Here is a quick programming example that tells you what keys you are pushing.




'--- ~ BEGIN ~

CLS    'clear the screen... Duh...
DO     'This starts the loop

press$ = INKEY$                     'Remember this?
IF press$ <> "" THEN PRINT press$    'This prints what press$ equalls...

LOOP UNTIL press$ = CHR$(27)   'CHR$(27) is the escape key...

'--- ~ Fin ~  'Escuse my french...




I know, that was lame joke...


Copy this programm and run it...
Notice what hapens when you press a key.  If it is a number or a letter
it prints what you pressed,  But what happens when you push an arrow key?
It Prints out a letter too!  Only the letter is a bit far to the right...
Whats that all about?
Actually, that is just kind of a glitch...  It doesn't mean to print out a
letter,  It wants to print out a number value but the computer won't let it.
How do we find out what number that represents?

Look at the last command...

LOOP UNTIL press$ = CHR$(27)

What is the CHR$(..) for?
If you have pressed the escape button in the program you would notice an
arrow pointing to the left...  That is a CHARACTER, just like a letter would
be...  the value for that character would be 27...
How did I know that?
In qbasic go to HELP,
       Goto CONTENTS,
Then to ASCII Character Codes, and double click...
Look at the character numbered 27...  Isn't that the same thing you got when
you pushed the escape key in the programm??!!  And what is that in
parenthesis next to it?  It says (ESC), Doesn't that look a lot like the
word ESCAPE?  I wonder why...

So, you know what the number for the escape button is but what is the CHR$
for?  the last command could actually be done like this...

LOOP UNTIL press$ = "<-"

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
NOTICE...  This text editor "NOTEPAD.exe"  Can't draw the actual character..
           So I had to use TWO...
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

But, since we know what the value of the escape key is, and we don't actually
have a <- button lets use its character value of 27... But how do we convert
a number into a character?  You guessed it.  CHR$(..)...

---

GREAT!  We understand that, now how do we find the characters for the arrow
keys...  If you notice when you press the arrow keys in your program it
shows " K" or " H" and not just "K" or "H"...  There is a little space before
it...  Beleive it or not that is the character 0...  If you look up that
character in the ASCII Character Codes under 0 you would see nothing. and
right next to it you would see (NUL)...  This is an empty character...

So if you think about it, when you press an arrow key you arn't telling the
computer one character like you would if you pushed the letter D or like you
would pushing the ESCAPE key.  When you press an arrow key the keyboard
gives the computer Two characters.  That means it is impossible to use
the command like this...

if press$ = chr$(number) then...

I know, that doesn't make it any easier...
What would you do then?  If you are giving a computer to charater values you
must add them together. so, it would look like this...

if press$ = chr$(number) + chr$(number) then...

That would work!
We allready know the first chr$ value right? It is 0 (nul)...
so, the first of the command would look like this.  Yes, I know that
anything added to Zero shouldn't be changed, but this is different in
programming...  You need the +...

if press$ = chr$(0) + chr$(?...

Now, we have to figure out the second value of the second character...
run that one program that tells you the character values of the keyboard
and push the right arrow...  What do you get?  " M" Right?
That is Null and then a captital M...
We have the first character, the Null chr$(0)
we will have to look up the second one...
go to the ASCII Character Codes and look up the Captial M...
The captial M is the number 77...  That is our second and final number...

the finished command line is...

if press$ = chr$(0) + chr$(77) then...

Thats it!!!  We know how to move right!!! HA HA HA HAAA!! That feels good!!

And I bet you TEN BUCKS that if you have read this, you know how to find
the other arrow key values...

Lets test to see if this is actually the RIGHT arrow key...

'--- BEGIN SHORT PROGRAM >>>

CLS
SCREEN 13

DO
press$ = INKEY$
IF press$ = CHR$(0) + CHR$(77) THEN x = x + 1
PSET (x, 50), 15
LOOP UNTIL press$ = CHR$(27)

'--- END...



IF you press any key but the right arrow key it won't move...
IT WORKS!!!

Now here are a list of the other arrow presses...

CHR$(0) + CHR$(77) Is RIGHT

CHR$(0) + CHR$(75) IS LEFT

CHR$(0) + CHR$(72) IS UP

CHR$(0) + CHR$(80) IS DOWN

THATS IT!!!!!

-----------------------------------------------------------------------------

OK, Whats Next!?
I covered collision detection,
I covered how to move a sprite,
What else is there in making a good game?

To tell you the truth, I have no Idea.
That is, other than a basic Idea of what kind of game you want to make and
how this game will be played for fun.  I admit that I don't know how to make
my own game.  I have programmed many many games, but they all follow a
certain theme.  Like Pong or Pacman.  I don't think I have had one original
idea...  I wish I could add how to think up a good game, but I can't.  That
would make this a very very good game tutorial.  Like I said in the first
Tutorial, 
"You can memorize every command that QBASIC has and still not know how to
programm..."
This can also be true for game programming.

"You can reprogram Pong and Pacman from scratch and still not know how to
make a good game..."

Come up with an original Idea...  Strain you brain for hours and hours if
you have to!  While your sitting in school detention or the O.R room or the
I.S.S room or whatever you have at your school, spend time thinking up an
original idea.  Draw your own sprites.  Make your own sounds.

And most importantly of all, Don't change the name of other peoples source
code!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

I realy hate when people do that.  If you copy some of the persons source
code make sure you give them recognition for it...

I myself give you the right to use anything that you learned from these
tutorials without giving me recognition, but, just remember where you
learned it...  I really don't expect to be in your games credits.  But I am
sure some people whose source you ripped off just might...  If you forget
where you got it from just mention that...

This is different when you learn how to do this on your own, or when you
have learned it directly from the source code.  I don't think tecniques
need a name...

---
Man this tutorial sucked...
It should've been called the ARROW KEY TUTORIAL FROM HELL!!
Another lame joke... I know I know...


-----------------------------------------------------------------------------
*****************************************************************************
-----------------------------------------------------------------------------

Thats it for this tutorial, If I didn't get into enough detail in the
explanations then just look at the source code and try to figure it out
on your own.  All else fails E-Mail Me...

My current E-Mail address is RADIOHANDS@AOL.com

If you are using this tutorial on your page, please leave the tutorial 
exactly as it is... please don't change anything, unless its spelling
errors... Theres alot of them! I don't like using the backspace key...

The original website that these were on is

http://members.aol.com/radiohands/index.html

Thank you
Vic Luce
Finished
November 28
1999

If you want to be notified when a new tutorial is out..
Send An E-mail to RADIOHANDS@AOL.com
with the subject saying VQBLIST and then your E-mail address(check website)

